package leetcode.weekly.week290;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import leetcode.IDebug;

public class Solution1 implements IDebug {

	public List<Integer> intersection(int[][] nums) {

		Set<Integer> set = new HashSet<>();

		for (int i = 0; i < nums.length; i++) {
			int[] num = nums[i];
			if (i == 0) {
				for (int j = 0; j < num.length; j++) {
					set.add(num[j]);
				}
			} else {
				Set<Integer> tmp = new HashSet<>();
				for (int j = 0; j < num.length; j++) {
					if (set.contains(num[j])) {
						tmp.add(num[j]);
					}
				}
				set = tmp;
			}
		}
		List<Integer> ans = new ArrayList<>(set);
		Collections.sort(ans);
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
